<template>
	<view class="page-product-add">
		<view class="module">
			<view class="module-header">商品名称</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="请输入商品名称" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">商品介绍</view>
			<view class="module-input">
				<textarea
					class="input-textarea"
					placeholder="请输入商品介绍"
					auto-height
				/>
			</view>
		</view>
		<view class="module">
			<view class="module-header">
				商品图片（长按图片可拖动图片顺序或删除）
			</view>
			<view class="module-image">
				<view class="item" v-for="(item, index) in imgArr" :key="index">
					<image class="media-object" :src="item" mode="widthFix" />
				</view>
				<view class="item button-upload" @tap="handleChoose">+</view>
			</view>
		</view>
		<view class="module">
			<view class="module-header">商品价格</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="请输入商品价格" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">运费</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="请输入运费" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">产品品牌</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="请输入库存" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">颜色</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">体积</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">重量</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">规格</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="" />
			</view>
		</view>
		<view class="module">
			<view class="module-header">库存</view>
			<view class="module-input">
				<input type="text" class="uni-input" placeholder="请输入库存" />
			</view>
		</view>

		<view class="module">
			<view class="module-header">分类至</view>
			<view class="module-input">
				<view class="uni-list-cell-db">
					<picker
						@change="bindPickerChange"
						:value="reasonIndex"
						:range="reasonArr"
					>
						<view class="input-select">
							{{ reasonArr[reasonIndex] }}
							<text class="iconfont iconjiantou" />
						</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="module-button"><button type="main">添加</button></view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			reasonIndex: '0',
			reasonArr: ['默认分类', '蔬菜', '生鲜'],
			imgArr: [],
		};
	},
	onLoad() {},
	methods: {
		bindPickerChange: function (e) {
			window.console.log('picker发送选择改变，携带值为', e.target.value);
			this.reasonIndex = e.target.value;
		},
		handleChoose() {
			uni.chooseImage({
				count: 3, // 默认9
				sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], // 从相册选择
				success: (res) => {
					window.console.log(JSON.stringify(res.tempFilePaths));
					this.imgArr = this.imgArr.concat(res.tempFilePaths);
				},
			});
		},
	},
};
</script>

<style lang="scss">
.page-product-add {
	padding: 24rpx 32rpx;
	.module {
		margin: 0 0 24rpx;
	}
	.module-header {
		color: #888;
		padding: 0 0 10rpx;
		font-size: 26rpx;
	}
	.module-image {
		display: flex;
		flex-wrap: wrap;
		.item {
			width: 1/3 * 100%;
			max-width: 1/3 * 100%;
			min-width: 1/3 * 100%;
			padding: 0 12rpx 24rpx;
			box-sizing: border-box;
		}
	}
	.module-input {
		.iconjiantou {
			float: right;
		}
		.input-select {
			background: #fff;
			padding: 10rpx;
			border: 1px solid #eee;
			border-radius: 10rpx;
		}
	}
	.uni-input {
		padding: 7px 20px;
		border: 1px solid #ddd;
	}
	.input-textarea {
		background: #fff;
		width: auto;
		border: 1px solid #ddd;
		border-radius: 10rpx;
		min-height: 200rpx;
		padding: 16rpx;
		font-size: 28rpx;
		margin: 0;
		.uni-textarea-textarea {
			width: 100%;
		}
	}
	.uni-form-item {
		background: #fff;
		padding: 0;
		.title {
			width: 140rpx;
			padding: 10rpx 16rpx;
		}
		.uni-input {
			padding: 14rpx;
			border: 1px solid #eee;
		}
	}
	.module-button {
		padding: 32rpx 0 0;
	}
	.button-upload {
		background: #fff;
		width: 200rpx;
		height: 200rpx;
		font-size: 90rpx;
		line-height: 200rpx;
		text-align: center;
		border: 1px solid #eee;
		color: #999;
	}
	.media-object {
		width: 100%;
		max-width: 100%;
	}
}
</style>
